var mysql  =require('mysql');
var dbConfig = require('../db/dbConfig');
var userSQL = require('../db/usersql');
var express = require('express');
var router = express.Router();



var pool = mysql.createPool(dbConfig.mysql);
var responseJSON = function(res,ret){
	if(typeof ret ==='undifind'){
		res.json({
			code:'-200',
			msg:'操作失败'
		})
	}else{
		res.json(ret);
	}
}
router.get('/goodsList',function(req,res,next){
	var data = {};
	var _res = res;
	pool.getConnection(function(err,connection){
		connection.query(userSQL.queryAllCar,function(err,res){
			console.log(res);
			data.result = res;
			data.code  = 200;
				if(err) data.err = err;
			//一json的形式返回给前台
			setTimeout(function(){
				responseJSON(_res,data)
			},300)
			//释放链接
			connection.release();
		})
	})
})

module.exports = router;


